import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/utils/cash_utils.dart';
import 'package:finance_app/src/widgets/form/form_edit_status_inherited_widget.dart';
import 'package:flutter/material.dart';
import 'package:finance_app/src/entities/format/service_and_product_entity.dart';

class ServiceAndProductFormItem extends StatelessWidget {
  final ServiceAndProductEntity productEntity;
  final bool hasError;
  final bool showHeader;
  final VoidCallback onTap;
  final bool isLastElement;

  const ServiceAndProductFormItem({
    Key key,
    this.onTap,
    this.hasError = false,
    this.showHeader = false,
    this.productEntity,
    this.isLastElement = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PressedOpacityButton(
      onPressed:
          FormEditStatusInheritedWidget.ofEnable(context) ? onTap : () {},
      child: Container(
        decoration: BoxDecoration(
            color: Colors.white,
            border: isLastElement
                ? null
                : Border(
                    bottom: BorderSide(
                    color: aceGrayColor,
                    width: getDp(0.5),
                  ))),
        padding:
            EdgeInsets.symmetric(horizontal: getDp(35), vertical: getDp(10)),
        child: Row(
          children: [
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  if (showHeader)
                    Padding(
                      padding: EdgeInsets.only(
                        bottom: getDp(5),
                      ),
                      child: Text(
                        S.current.item,
                        style: TextStyle(
                          color: aceDarkGrayColor,
                          fontSize: getSp(14),
                          fontWeight: FontWeight.w400,
                          height: 1,
                        ),
                      ),
                    ),
                  Text(
                    productEntity?.name ?? '',
                    style: TextStyle(
                      color: FormEditStatusInheritedWidget.ofEnable(context)
                          ? aceBlueColor
                          : aceBlackColor,
                      fontSize: getSp(18),
                      fontWeight: FontWeight.w700,
                      height: 14 / 18,
                    ),
                  ),
                  SizedBox(
                    height: getDp(5),
                  ),
                  if (Config.currentCompany.enableGst == 1)
                    Text(
                      '${productEntity.rate}% ${productEntity.key}',
                      style: TextStyle(
                        color: FormEditStatusInheritedWidget.ofEnable(context)
                            ? aceBlueColor
                            : aceBlackColor,
                        fontSize: getSp(14),
                        fontWeight: FontWeight.w400,
                        height: 14 / 14,
                      ),
                    ),
                ],
              ),
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                if (showHeader)
                  Padding(
                    padding: EdgeInsets.only(
                      bottom: getDp(5),
                    ),
                    child: Text(
                      S.current.amount,
                      style: TextStyle(
                        color: aceDarkGrayColor,
                        fontSize: getSp(14),
                        fontWeight: FontWeight.w400,
                        height: 1,
                      ),
                    ),
                  ),
                Text(
                  '${CashUtils.formatCashAmount(productEntity.discountedAmount)}',
                  style: TextStyle(
                    color: hasError
                        ? aceRedColor
                        : (FormEditStatusInheritedWidget.ofEnable(context)
                            ? aceBlueColor
                            : aceBlackColor),
                    fontSize: getSp(18),
                    fontWeight: FontWeight.w700,
                    height: 14 / 18,
                  ),
                ),
                SizedBox(
                  height: getDp(5),
                ),
                Text(
                  '${productEntity.number} x ${CashUtils.formatCashAmount(productEntity.amount)} ${productEntity.displayDiscountAmount}',
                  style: TextStyle(
                    color: hasError
                        ? aceRedColor
                        : (FormEditStatusInheritedWidget.ofEnable(context)
                            ? aceBlueColor
                            : aceBlackColor),
                    fontSize: getSp(14),
                    fontWeight: FontWeight.w400,
                    height: 14 / 14,
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
